# @Time : 2021/4/8 9:59
# @Author : Fioman 
# @Phone : 13149920693
"""
webSocket的单例类,用来创建和web进行通信的单例实例
"""
import threading
import queue


def synchronized(func):
    """
    线程安全的装饰器,加一个线程锁
    :param func:
    :return:
    """
    func.__lock__ = threading.Lock()

    def lock_func(*args, **kwargs):
        with func.__lock__:
            return func(*args, **kwargs)

    return lock_func


class WebSocketQueue(object):
    """
        单例日志类
        """
    __websocketQueue__ = None
    __initFlag__ = False

    @synchronized
    def __new__(cls, *args, **kwargs):
        if cls.__websocketQueue__ is None:
            cls.__websocketQueue__ = object.__new__(cls)
        return cls.__websocketQueue__

    def __init__(self):
        if not self.__initFlag__:
            print("WebSocketQueue.__init__() 进行初始化")
            self.__initFlag__ = True
            self.websocketQueue = queue.Queue()


